<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>防抖</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            background: lightblue;
        }

        input {
            width: 100px;
            height: 100px;
            border-radius: 10px;
            font-size: 30px;
        }
    </style>
</head>
<body>
    <input type="button" value="剁手">
    <p></p>
    <script>
        const button = document.querySelector('input');
        const text = document.querySelector('p');

        function payMoney() {
            text.innerText = '已剁';
        }

        function debounce (func, delay) {
            let timer;
            return function() {
                let context = this;
                let args = arguments;
                clearTimeout(timer);
                timer = setTimeout(function() {
                    func.apply(context, args);
                }, delay);
            }
        }
        button.addEventListener('click', debounce(payMoney, 1000))

        // 防抖：规定时间内发生抖动是不执行后续操作
        // 节流：规定时间间隔内后续动作只会执行一次
    </script>
</body>
</html>